SHELL_FILES_ALL := $(shell find -type f -perm /a+x | grep -vE "/(\.git|debian/.*)/" \
	| xargs grep -lI '^\#!/bin/.*sh')

SHELL_FILES_DASH = $(shell echo "$(SHELL_FILES_ALL)" | xargs grep -l '^\#!/bin/sh$$')
SHELL_FILES_BASH = $(shell echo "$(SHELL_FILES_ALL)" | xargs grep -l '^\#!/bin/bash$$')
# we allow external scripts to be sourced
SHELLCHECK_CALL = shellcheck -x


.PHONY: test
test: test-shell

.PHONY: test-shell
test-shell:
	@if [ -n "$(SHELL_FILES_BASH)" ]; then $(SHELLCHECK_CALL) $(SHELL_FILES_BASH); fi
	@if [ -n "$(SHELL_FILES_DASH)" ]; then $(SHELLCHECK_CALL) --shell dash $(SHELL_FILES_DASH); fi
